package com.personal.common.util;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.core.convert.converter.Converter;

public class StringToDate implements Converter<String, Date> {

	@Override
	public Date convert(String param) {
		Date date = null;
		if (StringUtils.isNotEmpty(param)) {
			try {
				date = DateUtils.parseDate(param, new String[] { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss",
						"yyyy-MM-dd HH:mm", "yyyy-MM-dd" });
			} catch (ParseException e) {
				throw new RuntimeException(e);
			}
		}
		return date;
	}

}
